package com.cxyd.common.interceptor;

import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.UUID;

@Component
public class CustomHeaderInterceptor implements ClientHttpRequestInterceptor {

    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        // 添加X-LR-REQUEST-ID请求头，值为随机UUID
        request.getHeaders().set("X-LR-REQUEST-ID", UUID.randomUUID().toString());

        // 可选：添加其他常用请求头
        request.getHeaders().set("Content-Type", "application/json");
        request.getHeaders().set("Accept", "application/json");

        return execution.execute(request, body);
    }
}
